package com.neusoft.controller;

import com.neusoft.domain.Employee;
import com.neusoft.domain.Result;
import com.neusoft.domain.ResultPage;
import com.neusoft.service.EmployeeService;
import com.neusoft.service.impl.EmployeeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employees")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/findEmployeeByPage")
    public Result<ResultPage<Employee>> findEmployeeByPage(Integer page,Integer pageSize,String account,String nickname,String telephone){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        ResultPage<Employee> resultPage = employeeService.findEmployeeByPage(page,pageSize,account,nickname,telephone);
        // 3. 响应数据给前端
        return Result.success(resultPage);
    }

    @PostMapping("/saveEmployee")
    public Result saveEmployee(@RequestBody Employee employee){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        employeeService.saveEmployee(employee);
        return Result.success();
    }

    @PutMapping("/updateEmployee")
    public Result updateEmployee(@RequestBody Employee employee){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        employeeService.updateEmployee(employee);
        // 3. 相应数据给前端
        return Result.success();
    }

    @PutMapping("/updateEmployeeStatus")
    public Result updateEmployeeStatus(@RequestBody Employee employee){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        employeeService.updateEmployeeStatus(employee);
        // 3. 相应数据给前端
        return Result.success();
    }


}
